{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# %%writefile 1.py\n",
    "# 项目地址\n",
    "# https://easytrader.readthedocs.io/zh/master/usage/\n",
    "# 文档\n",
    "# https://easytrader.readthedocs.io/zh/master/usage/#3\n",
    "\n",
    "\n",
    "import jqktrader\n",
    "from jqktrader.log import logger\n",
    "\n",
    "user = jqktrader.use()\n",
    "\n",
    "user.connect(\n",
    "  exe_path=r'C:\\同花顺软件\\同花顺\\xiadan.exe',\n",
    "  tesseract_cmd=r'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 7-29日待测试\n",
    "# 获取资金状况\n",
    "user.balance\n",
    "# 获取持仓\n",
    "user.position"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 7-29日待测试\n",
    "user.buy('601238', price=7.82, amount=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "user.cancel_entrust('0262839113')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 7-29日待测试\n",
    "# 获取持仓\n",
    "user.position"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 获取资金状况\n",
    "user.balance\n",
    "# 获取持仓\n",
    "user.position\n",
    "# 查询委托\n",
    "user.today_entrusts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 买入\n",
    "user.buy('162411', price=0.55, amount=100)\n",
    "# 卖出\n",
    "user.sell('162411', price=0.55, amount=100)\n",
    "# 撤单\n",
    "user.cancel_entrust('buy/sell 获取的 entrust_no')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = user.buy('000878', price=12.45, amount=100)\n",
    "# {'entrust_no': '4723950167'}\n",
    "a\n",
    "user.cancel_entrust(a['entrust_no'])\n",
    "# {'message': 'success'}"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (ths_jy)",
   "language": "python",
   "name": "ths_jy"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
